package alp.starcode.sanping.framework.base;

import cn.hutool.core.bean.BeanUtil;
import lombok.SneakyThrows;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

/**
 * 基础DTO
 *
 * @author liwang
 * @date 2023/4/11 15:02
 */
public class BaseDTO<T> extends Base {

    /**
     * 类型装换方法
     *
     * @return T
     */
    @SneakyThrows
    public T converter() {
        Type actualTypeArgument = ((ParameterizedType) this.getClass().getGenericSuperclass()).getActualTypeArguments()[0];
        Class<T> tClass = (Class<T>) actualTypeArgument;
        return BeanUtil.copyProperties(this, tClass);
    }

}
